<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.hotel.jabc.DbUtil"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%--@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="logHotel" --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	request.setCharacterEncoding("utf-8");
	response.setCharacterEncoding("utf-8");
	response.setContentType("charset=utf-8;html/text");	
%>
<%@ page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录验证</title>
</head>
<body>
<%
	/* 获取页面跳转的数据 */
	String username=request.getParameter("username"); //用户
	String password=request.getParameter("password"); //密码
	String confimpassword=request.getParameter("confirmPassword"); //重复密码
	String gender=request.getParameter("sex"); //性别
	String telNum=request.getParameter("iphone"); //联系电话
	String email=request.getParameter("email"); //邮箱
	String realName=request.getParameter("realName"); //真实姓名
%>
<%
	 try{
		String driverName="com.mysql.jdbc.Driver";
		String url="jdbc:mysql://localhost:3306/hotel";
		String userName="root";
		String passWord="root";
		
		Class.forName(driverName);
		Connection con=DriverManager.getConnection(url,userName,passWord);
		String sql="select * from adinfo where adname=? and adpwd=? ;";
		PreparedStatement pstat=con.prepareStatement(sql);
		pstat.setString(1, username);
		pstat.setString(2, password);
		ResultSet rs=pstat.executeQuery(); //执行查询
		if(rs.next()){ //如果账号跟密码存在
			String aName=rs.getString("adname");
			String aPass=rs.getString("adpwd");
			String alevel=rs.getString("adlevel");
			out.print("登录成功");
			//1.通过request传递
			session.setAttribute("userName",aName);
			//2.RequestDispatcher转发器和转发方法
			RequestDispatcher rd= request.getRequestDispatcher("index.jsp");
			rd.forward(request, response);
		}else{
			out.println("用户名或者密码不正确");
		}
		if (con != null && !con.isClosed()) {
	        con.close();
	      }
	}catch(ClassNotFoundException e) {
	      e.printStackTrace();
	    } catch (SQLException e) {
	      e.printStackTrace();
	    } 
%>

</body>
</html>